package com.love.cloud.common.mybatis.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill;
import com.github.yulichang.injector.MPJSqlInjector;
import com.love.cloud.common.mybatis.method.DeletePhysicsByIdMethod;
import com.love.cloud.common.mybatis.method.ReplaceBatch;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义SQl默认注入器
 * @author hongdongqu
 * @version 1.0
 */
@Component
public class MySqlInjector extends MPJSqlInjector {
    /**
     * 注入自定义的方法
     * @param mapperClass
     * @return
     */
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
        List<AbstractMethod> methodList=super.getMethodList(mapperClass);
        //添加自定义物理删除的方法
        methodList.add(new DeletePhysicsByIdMethod());
        methodList.add(new ReplaceBatch());

        //以下为MP提供的选装件
        methodList.add(new InsertBatchSomeColumn(t->!t.isLogicDelete()&&!t.getColumn().equals("version")));
        methodList.add(new LogicDeleteByIdWithFill());
        methodList.add(new AlwaysUpdateSomeColumnById(t->t.getColumn().equals("name")));
        return methodList;
    }
}
